@extends('admin.layouts.head')

@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item active" aria-current="page">客服等级</li>
                            </ol>
                        </nav>
                        @verbatim
                        <div class="card">
                            <div class="card-body">

                                <div id="vueApp">
                                    <div class="content-box">

                                        <div class="top-bar" style="padding: 20px 0;">
                                            <el-button type="primary" @click="editLevel({reward:{}})">添加客服等级</el-button>
                                        </div>


                                        <el-table
                                            :data="dataList"
                                            border
                                            size="mini"
                                            style="width: 100%">
                                            <el-table-column
                                                prop="id"
                                                label="ID"
                                                width="80"
                                            >
                                            </el-table-column>
                                            <el-table-column
                                                prop="name"
                                                label="名称"
                                            >
                                            </el-table-column>
                                            <el-table-column
                                                prop="start_vip_title"
                                                label="起始VIP"
                                            >
                                            </el-table-column>
                                            <el-table-column
                                                prop="end_vip_title"
                                                label="结束VIP"
                                            >
                                            </el-table-column>
                                            <el-table-column
                                                prop=""
                                                label="操作"
                                                width="120"
                                            >
                                                <template slot-scope="scope">
                                                    <el-button @click="editLevel(scope.row)" type="primary" round plain size="small">编辑</el-button>
                                                </template>
                                            </el-table-column>

                                        </el-table>


                                        <!-- 保存窗口 -->
                                        <el-dialog
                                            title="保存等级"
                                            :visible.sync="saveShow"
                                            width="600"
                                        >
                                            <div class="save-win" style="margin-right: 30px;">
                                                <el-form ref="saveForm" :model="saveForm" label-width="100px">
                                                    <el-form-item label="名称">
                                                        <el-input v-model="saveForm.name"></el-input>
                                                    </el-form-item>
                                                    <el-form-item label="起始VIP">
                                                        <el-select v-model="saveForm.start_vip" placeholder="请选择">
                                                            <el-option
                                                                v-for="item in userLevelList"
                                                                :key="item.id"
                                                                :label="item.title"
                                                                :value="item.id">
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                    <el-form-item label="结束VIP">
                                                        <el-select v-model="saveForm.end_vip" placeholder="请选择">
                                                            <el-option
                                                                v-for="item in userLevelList"
                                                                :key="item.id"
                                                                :label="item.title"
                                                                :value="item.id">
                                                            </el-option>
                                                        </el-select>
                                                    </el-form-item>
                                                    <el-form-item label="奖励" v-if="saveForm.start_vip && saveForm.end_vip">
                                                        <div
                                                        v-for="item in userLevelList" :key="item.id"
                                                        v-if="item.id >= saveForm.start_vip && item.id <= saveForm.end_vip"
                                                        >
                                                            <el-input placeholder="请输入内容" v-model="saveForm.reward[+item.id]">
                                                                <template slot="prepend">{{item.title}}</template>
                                                            </el-input>
                                                        </div>
                                                    </el-form-item>
                                                    <el-form-item>
                                                        <el-button type="primary" @click="saveLevel">保存</el-button>
                                                        <el-button @click="saveShow=false">取消</el-button>
                                                    </el-form-item>
                                                </el-form>
                                            </div>
                                        </el-dialog>

                                    </div>

                            </div> <!-- .card-body -->
                        </div> <!-- .card -->
                        @endverbatim
                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->

    @include('admin.layouts.vuehead')

    <script>
        const vueApp = new Vue({
            el: '#vueApp',
            data() {
                return {
                    queryForm: {

                    },
                    dataList: [],
                    saveShow: false,
                    saveForm: {
                        id : 0,
                        name: "",
                        reward: {},
                        start_vip: 0,
                        end_vip:0,
                    },
                    userLevelList: [],
                }
            },
            mounted() {
                this.getList()
                this.getUseLevel()
            },
            watch: {

            },
            methods: {
                getList() {
                    adminApi_getCustomServiceLevelList(this.queryForm).then(res => {
                        this.dataList = res.data
                    })
                },
                getUseLevel() {
                    adminApi_getUserLevelList({}).then(res => {
                        this.userLevelList = res.data
                    })
                },
                saveLevel() {
                    adminApi_saveCustomServiceLevel(this.saveForm).then(res => {
                        this.$message.success('保存成功')
                        this.saveShow = false
                        this.getList()
                    }).catch(err => {
                        this.$message.error(err.message)
                    })
                },
                editLevel(row) {
                    this.saveForm = row
                    this.saveShow = true
                },
            },
        })
    </script>
    </body>

@endsection
